You are here: Symbol Reference > Dew Namespace > Dew.Stats Namespace > Dew.Stats.Units Namespace > Classes > Statistics Class > Statistics Methods > CorrCoef Method > Statistics.CorrCoef Method ([In] TDenseMtxVec, [In] TDenseMtxVec, [In] TMtx)
Dew Stats for .NET
ContentsIndexHome
PreviousUpNext
Statistics.CorrCoef Method ([In] TDenseMtxVec, [In] TDenseMtxVec, [In] TMtx)

Pearson correlation coefficients.

Syntax
C#
Visual Basic
public static void CorrCoef([In] TDenseMtxVec X, [In] TDenseMtxVec Y, [In] TMtx aResult);
Parameters 
Description 
[In] TDenseMtxVec X 
Defines first sample (variable) values (observables). 
[In] TDenseMtxVec Y 
Defines second sample (variable) values (observables). 
[In] TMtx aResult 
Returns Pearson correlation coefficients bewteen samples X and Y. Size of Result is adjusted automatically. 

Calculates Person correlation coefficients between X and Y representing two samples/variables with X and Y Values being treated as observables. 

If X and Y are two matrices, the rouitine calculates Pearson correlation coefficients rx,y between X and Y matrix. The algorithm assumes X and Y are two samples (variables) and all X are are treated as it's observables (same goes for Y). 

Note The correlation is defined only if both of the standard deviations are finite and both of them are nonzero. 

 

Correlation coefficient 

The correlation coefficient rho between two random variables is defined by the following equation: 

 

where x,y are two variables, Cov covariance betwen x and y, sigma(s) their expected standard deviations and E-s their expected values. If the variables are independent then the correlation is 0, but the converse is not true because the correlation coefficient detects only linear dependencies between two variables. 

Sample correlation coefficients. 

If we have a series of n measurements of X and Y, then the Pearson product-moment correlation coefficient can be used to estimate the correlation of X and Y. The Pearson coefficient is also known as the "sample correlation coefficient". The Pearson correlation coefficient is then the best estimate of the correlation of X and Y .

Calculate correlation coefficients from Data1 and Data2 representing two variables.

using Dew.Math; using Dew.Stats.Units; namespace Dew.Examples { private void Example() { Vector data1 = new Vector(0); Vector data2 = new Vector(0); Matrix corr = new Matrix(0,0); data1.SetIt(false, new double[] {1,2,3}); data2.SetIt(false, new double[] {5, 5.5, 1.0} ); Statistics.CorrCoef(data1,data2,corr); // corr = [1.00000000, -0.81088485, // -0.81088485, 1.00000000] } }
Copyright (c) 1999-2024 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!